package com.it.commicity.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private int code;
    private Boolean success;
    private String msg;
    private T data;

    public static Result success() {
        return new Result(200, true, null, null);
    }

    public static Result success(String msg, Object data) {
        return new Result(200, true, msg, data);
    }

    public static Result success(Object data) {
        return new Result(200, true, null, data);
    }

    public static Result fail(String errorMsg) {
        return new Result(400, false, errorMsg, null);
    }

    public static Result fail(ResultCodeEnum codeEnum) {
        return new Result(codeEnum.getCode(), false, codeEnum.getMessage(), null);
    }

    public static Result fail(Integer code, String message) {
        return new Result(code, false, message, null);
    }
}
